package com.example.entity;




import java.util.List;


public class ResponseResult<T> {

    public static final int OK_CODE = 200;

    public static final int FAIL_CODE = 500;



    private int code;


    private String message;


    private T data;


    private List<T> dataList;


    private Integer total;

    public ResponseResult() {
    }

    private ResponseResult(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public ResponseResult(int code, String message, List<T> dataList) {
        this.code = code;
        this.message = message;
        this.dataList = dataList;
    }

    public ResponseResult(int code, String message, List<T> dataList, Integer total) {
        this.code = code;
        this.message = message;
        this.dataList = dataList;
        this.total = total;
    }

    public static <T> ResponseResult<T> success(int row) {
        if(row > 0) return new ResponseResult<>(OK_CODE, "成功", null);
        else return new ResponseResult<>(FAIL_CODE, "失败", null);
    }

    public static <T> ResponseResult<T> success() {
        return new ResponseResult<>(OK_CODE, "成功", null);
    }

    public static <T> ResponseResult<T> success(T data) {
        return new ResponseResult<T>(OK_CODE, "成功", data);
    }

    public static <T> ResponseResult<T> success(List<T> listData) {
        return new ResponseResult<T>(OK_CODE, "成功", listData);
    }
    public static <T> ResponseResult<T> success(List<T> listData,Integer total) {
        return new ResponseResult<T>(OK_CODE, "成功", listData,total);
    }

    public static <T> ResponseResult<T> success(String msg, T data) {
        return new ResponseResult<>(OK_CODE, msg, data);
    }

    public static <T> ResponseResult<T> fail() {
        return new ResponseResult<>(FAIL_CODE, "失败", null);
    }

    public static <T> ResponseResult<T> fail(String msg) {
        return new ResponseResult<T>(FAIL_CODE, msg, (T) null);
    }

    public static <T> ResponseResult<T> fail(String msg, T data) {
        return new ResponseResult<>(FAIL_CODE, msg, data);
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public List<T> getDataList() {
        return dataList;
    }

    public void setDataList(List<T> dataList) {
        this.dataList = dataList;
    }

    public Integer getTotal() {
        return total;
    }

    public void setTotal(Integer total) {
        this.total = total;
    }
}
